 // pages/find/find.js
const app = getApp()
var base_url = app.globalData.url
var template = require('../template/template.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    width:"33%",
    home: {
      "current": 0,
      "pagePath": "/pages/home/ptwords/ptwords",
      "iconPath": "/images/icons/icona_a.png",
      "text": "习字"
    },
    // photo: {
    //   "current": 0,
    //   "pagePath": "/pages/photo/goTest/goTest",
    //   "iconPath": "/images/icons/icon1.png",
    //   "text": "评测"
    // },
    mine: {
      "current": 0,
      "pagePath": "/pages/my/visitor/mine/mine",
      "iconPath": "/images/icons/icon4_1.png",
      "text": "我的"
    },
    find: {
      "current": 0,
      "pagePath": "/pages/find/find",
      "iconPath": "/images/icons/icon3_1.png",
      "text": "班级"
    },
    store: {
      "current": 0,
      "pagePath": "/pages/store/storeHome/storeHome",
      "iconPath": "/images/icons/store_1.png",
      "text": "助学"
    },
    multiArray: [['一年级', '二年级','三年级','四年级','五年级','六年级'], ['一班', '二班','三班','四班','五班','六班','七班','八班','九班','十班','十一班','十二班','十三班','十四班','十五班','十六班','十七班','十八班','十九班','二十班']],//二维数组，长度是多少是几列
    multiIndex: [0, 0],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getSystemInfo({

      success: function (res) {
        let clientHeight = res.windowHeight;
        let clientWidth = res.windowWidth;
        let ratio = 750 / clientWidth;
        let height = clientHeight * ratio;
        that.setData({
          height: clientHeight
        });
      }
    });
    wx.getStorage({
      key: 'auth',
      success: function (res) {
        console.log(res.data)
        if (res['data'] == 1) {
          that.setData({
            mine: {
              "current": 0,
              "pagePath": "/pages/my/teacher/mine/mine",
              "iconPath": "/images/icons/icon4_1.png",
              "text": "我的"
            }
          })
        }
      },
      fail:function(res){
        wx.showModal({
          title: '提示',
          content: '请先登陆',
          success:function(res){
            if(res.confirm){
              wx.navigateTo({
                url: '../my/noauth/noauth',
                success: function (res) {
                  console.log(res)
                },
                fail: function () {
                }
              })
            }else{
              wx.navigateTo({
                url: '../home/ptwords/ptwords',
                success: function (res) {
                  console.log(res)
                },
                fail: function () {
                }
              })
            }
          }
        })
        that.setData({
          mine: {
            "current": 0,
            "pagePath": "/pages/my/noauth/noauth",
            "iconPath": "/images/icons/icon4_1.png",
            "text": "我的"
          }
        })
      }
    }) 

    // wx.getStorage({
    //   key: 'student_id',
    //   success: function (res) {
    //     wx.request({
    //       url: base_url+'/checkToday/',
    //       method: 'POST',
    //       data: {
    //         student_id: res['data'],
    //       },
    //       header: {
    //         "Content-Type": "application/x-www-form-urlencoded"
    //       },
    //       success: function (res) {
    //         if (res.data['check'] == '-1'){
    //           that.setData({
    //             check: '0'
    //           })
    //           wx.showModal({
    //             title: '今天还没留作业',
    //             content: '',
    //             success: function (res) {
                  
    //               if (res.confirm) {
    //                 console.log('弹框后点确定')
    //               } else {
    //                 console.log('弹框后点取消')
    //               }
    //             }
    //           })
    //         }else{
    //           console.log(res.data['check'])
    //           that.setData({
    //             check: res.data['check']
    //           })
    //         }
            
    //       }
    //     })
    //   },
    // })
    wx.getStorage({
      key: 'teacher_id',
      success: function (res) {
        wx.request({
          url: base_url + '/getAllexercise/',
          method: 'POST',
          data: {
            teacher_id: res.data
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          success: function (res) {
            if (res.data['flag'] == true) {
              console.log(res.data)
              that.setData({
                classDatas_lst: res.data['classDatas_lst'],
                exerciseDatas_lst: res.data['exerciseDatas_lst']
              })
              console.log(that.data.exerciseDatas_lst)
            } else {
              wx.redirectTo({
                url: '../noclass/noclass',
                success: function (res) {
                  console.log(res)
                },
                fail: function () {
                }
              })
            }
          }
        })


      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  gotoExerceselist:function(){
    wx.navigateTo({
      url: 'exerciselist/exerciselist',
      success: function (res) {
        console.log(res)
      },
      fail: function () {
      }
    })
  },
  gotoPhoto:function(){
    var that = this
    if (that.data.check == '0'){
      wx.showModal({
        title: '提示',
        content: '已经上传作业了',
        success: function (res) {
          if (res.confirm) {
            console.log('弹框后点确定')
          } else {
            console.log('弹框后点取消')
          }
        }
      })
      return
    }else{
      wx.navigateTo({
        url: 'exercisePhoto/exercisePhoto',
        success: function (res) {
          console.log(res)
        },
        fail: function () {
        }
      })
    }
    
  },
  bindMultiPickerChange: function (e) {
    var that = this
    var getindex = e.detail.value
    var grade = that.data.multiArray[0][getindex[0]]
    var className = that.data.multiArray[1][getindex[1]]
    console.log(grade+className)
  },
  bindMultiPickerColumnChange: function (e) {
    console.log('修改的列为', e.detail.column, '，值为', e.detail.value);
  },

  gotoClassmate:function(res){
    console.log(res)
    var getClassId = res.currentTarget.dataset.name
    wx.setStorage({
      key: 'getClassId',
      data: getClassId,
      success: function () {
        console.log(res)
      }
    })
    wx.request({
      url: base_url + '/getAllclassmates/',
      method: 'POST',
      data: {
        getClassId: getClassId
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        if (res.data['flag'] == true) {

          var that = this

          wx.setStorage({
            key: 'classmates_lst',
            data: res.data['classmates_lst'],
            success: function () {
              wx.navigateTo({
                url: 'classmate/classmate'
              })
            }
          })
          
        }
      }
    })
  },
  gotoSeemore:function(res){
    console.log(res)
    var getClassId = res.currentTarget.dataset.name
    wx.request({
      url: base_url + '/getAllclassesMore/',
      method: 'POST',
      data: {
        getClassId: getClassId
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        if (res.data['flag'] == true) {

          var that = this

          wx.setStorage({
            key: 'classSeemoreDatas',
            data: res.data['datas'],
            success: function () {
              wx.navigateTo({
                url: 'seeMore/seeMore'
              })
            }
          })

        }
      }
    })
  }
})